package com.open.launcher.base;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Created by Administrator on 2017/12/22 0022
 * function:
 */

public abstract class BaseRecycleViewAdapter<V extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<V>{
    public Context mContext;
    public static final int TYPE_HEADER = 0;  //说明是带有Header的
    public static final int TYPE_FOOTER = 1;  //说明是带有Footer的
    public static final int TYPE_NORMAL = 2;  //说明是带有header和footer的
    public static final int TYPE_NORMAL_TYPE1 = 3;  //说明是带有header和footer的
    public static final int TYPE_NORMAL_TYPE2 = 4;  //说明是带有header和footer的
    public View mHeaderView;
    public View mFooterView;
    public onItemClickListener listener;
    public onItemFocusChangeListener focusChangelistener;
    public interface onItemClickListener {
        void onItemClick(View v, int pos);
    }
    public interface onItemFocusChangeListener{
        void onItemFoucus(View view,boolean b);
    }
    public View getmHeaderView() {
        return mHeaderView;
    }

    public void setmHeaderView(View mHeaderView) {
        this.mHeaderView = mHeaderView;
    }

    public View getmFooterView() {
        return mFooterView;
    }

    public void setmFooterView(View mFooterView) {
        this.mFooterView = mFooterView;
    }

    public onItemClickListener getListener() {
        return listener;
    }

    public void setListener(onItemClickListener listener) {
        this.listener = listener;
    }
    public void setFocusChangelistener(onItemFocusChangeListener listener){this.focusChangelistener=listener;}

    /** 重写这个方法，很重要，是加入Header和Footer的关键，我们通过判断item的类型，从而绑定不同的view* */
    @Override
    public int getItemViewType(int position) {

        if (mHeaderView == null && mFooterView == null){
            return TYPE_NORMAL;
        }
        if (mHeaderView!=null&&position == 0){
            //第一个item应该加载Header
            return TYPE_HEADER;
        }
        if (mFooterView!=null&&position == getItemCount()-1){
            //最后一个,应该加载Footer
            return TYPE_FOOTER;
        }
//        switch (position+""){
//            case "0":
//                return
//            case "1":
//                return
//        }
        return TYPE_NORMAL;
    }

}
